package com.ytlz.dmcs.model.system.view;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.AuthenticationException;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ytlz.dmcs.config.SystemConfiguration;

@Controller
public class PublicView {
	@Autowired
	private SystemConfiguration config;
	
	@RequestMapping("/login")
	public String login(HttpServletRequest request,Model model) {
		if(request.getParameter("error")!=null) {
			
			AuthenticationException exception = (AuthenticationException)request.getSession().getAttribute("SPRING_SECURITY_LAST_EXCEPTION");
			System.out.println(exception.getMessage());
			model.addAttribute("errormsg", exception.getMessage());
		}else {
			model.addAttribute("errormsg", "");
		}
		
		model.addAttribute("apptitle", config.getApplicationName());
		return "login";
	}
	
	@RequestMapping("/wellcome")
	public String wellcome(Model model) {
		model.addAttribute("apptitle", config.getApplicationName());
		return "wellcome";
	}
}
